package com.gitee.feizns.quickstart.log.spring.boot.autoconfigure;

import com.gitee.feizns.quickstart.log.LogAroundAspect;
import com.gitee.feizns.quickstart.log.LogAroundAspectListener;
import com.gitee.feizns.quickstart.log.LogUserIdSupplier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * 日志数据库存储自动配置
 * @author feizns
 * @since 2025/1/6
 */
@Configuration
@EnableConfigurationProperties(QkLogProperties.class)
public class QkLogAutoConfigure {

    /**
     * 日志用户编号供应商
     */
    @Autowired(required = false)
    private LogUserIdSupplier logUserIdSupplier;

    /**
     * 日志切面
     * @param listeners 监听器列表
     * @return {@link LogAroundAspect}
     */
    @Bean
    public LogAroundAspect logAroundAspect(List<LogAroundAspectListener> listeners) {
        return new LogAroundAspect(this.logUserIdSupplier, listeners);
    }

}
